﻿﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Validation.aspx.cs" Inherits="Validation" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Scripts/IdCardvalidation.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <%-- RequiredFieldValidator控件：用于对一些必须输入信息的控件验证，如用户名/密码
                InitialValue属性：用于指定被验证控件的初始文本。只有在被验证控件中输入值与
                InitialValue值不同时，验证才通过。
                ValidationGroup：设置验证控件的分组名，不同组的不会响应，同组的响应
                ErrorMessage：控件中显示的错误信息，即验证失败时，显示的信息
                ControlToValidate：指定要验证控件的ID,即把验证控件与要验证控件绑定
                --%>
            <asp:Label ID="Label5" runat="server" Text="学号"></asp:Label>
            <asp:TextBox ID="TbNo" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TbNo" ErrorMessage="学号不能为空！" ValidationGroup="a"></asp:RequiredFieldValidator>
            <%-- RequiredFieldValidator控件：用来验证输入值是否和定义的正则表达式相匹配，
                常用来验证电话号码、邮政编码、Email等
                ValidationExpression属性：用来确定验证所需的正则表达式
                Display="Dynamic"：设置为动态，清除占位，界面更美观，没有空格--%>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TbNo" Display="Dynamic" ErrorMessage="学号必须为11位！" ValidationExpression="\d{11}" ValidationGroup="a"></asp:RegularExpressionValidator>
            <br />
            <asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label>
            <asp:TextBox ID="TbUserName" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TbUserName" ErrorMessage="用户名不能为空！" ValidationGroup="a"></asp:RequiredFieldValidator>
            <br />
            <asp:Label ID="Label2" runat="server" Text="密码"></asp:Label>
            <asp:TextBox ID="TbPassword" runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TbPassword" ErrorMessage="密码不能为空！" ValidationGroup="a"></asp:RequiredFieldValidator>
            <br /> 
&nbsp;&nbsp;
            <asp:TextBox ID="TbPassword2" runat="server" TextMode="Password"></asp:TextBox>
            <%-- CompareValidator控件：用于比较一个控件的值和另一个控件的值，若相等则验证通过
                ；也可以用于比较一个控件的值和一个指定的值，若比较的结果为Ture则验证通过
                ControlToCompare属性：指定与被验证控件比较的控件ID  
                ControlToValidate属性：指定要验证控件的ID,即把验证控件与要验证控件绑定
                ValueToCompare属性:指定与被验证控件比较的值 
                注意：ControlToCompare属性与ValueToCompare属性在应用时只能选择一个--%>
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TbPassword" ControlToValidate="TbPassword2" ErrorMessage="两次密码不相同！" ValidationGroup="a"></asp:CompareValidator>
            <br />
            <asp:Label ID="Label3" runat="server" Text="年龄"></asp:Label>
            <asp:TextBox ID="TbAge" runat="server"></asp:TextBox>
            <%-- RangeValidator控件：用来验证输入值是否在指定范围内
                MaximumValue属性：验证范围最大值
                MinimumValue属性：验证范围最小值--%>
            <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TbAge" ErrorMessage="不正确年龄" MaximumValue="120" MinimumValue="0" Type="Integer" ValidationGroup="a"></asp:RangeValidator>
            <br />
            <asp:Label ID="Label4" runat="server" Text="电子邮件"></asp:Label>
            <asp:TextBox ID="TbEmail" runat="server" TextMode="Email"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TbEmail" ErrorMessage="不正确的电子邮件地址" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="a"></asp:RegularExpressionValidator>
            <br />
            <asp:Label ID="Label6" runat="server" Text="身份证"></asp:Label>
            <asp:TextBox ID="TbIDCard" runat="server"></asp:TextBox>
            <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="CustomValidator1_ClientValidate" ControlToValidate="TbIDCard" ErrorMessage="非法身份证号码" OnServerValidate="CustomValidator1_ServerValidate" ValidationGroup="a">身份证校验失败</asp:CustomValidator>
            <br />
            <asp:Button ID="BtnSubmit" runat="server" Text="提交" ValidationGroup="a" />
            <br />
            <br />
            <%-- ValidationSummary控件：用于汇总其他验证控件错误信息的方式，即汇总其他验证控件
                的ErrorMessage属性值
                ShowMessageBox属性：指定是否在一个弹出的消息框中显示错误信息
                showSummary属性：指定是否启用错误信息汇总--%>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" ValidationGroup="a" />
            <br />
            <br />
            <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox1" ErrorMessage="不能为空！" ValidationGroup="b"></asp:RequiredFieldValidator>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="b" />
        </div>
    </form>
</body>
</html>